package org.hxyjs.service.impl;

import org.hxyjs.dao.CosttypeDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Costtype;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.CosttypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("CosttypeService")
public class CosttypeServiceImpl implements CosttypeService {
    @Resource
    CosttypeDao costtypeDao;
    @Override
    public DTO<Costtype> getAllCosttypes()  throws Exception{
        List<Costtype> costtypes = costtypeDao.getAllCosttypes();
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(costtypes).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Costtype>(messageEnum.getCode(),messageEnum.getMessage(),costtypes);
    }

    @Override
    public DTO<Costtype> deleteCosttypeByCono(String cono)  throws Exception{
        Integer result = costtypeDao.deleteCosttypeByCono(cono);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEADMINSUCCESS:MessageEnum.DELETEADMINFAIL;
        return new DTO<Costtype>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<Costtype> getCosttypeByCono(String cono)  throws Exception{
        Costtype costtypes = costtypeDao.getCosttypeByCono(cono);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(costtypes).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Costtype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Costtype> getCosttypesByPage(PageInfo pageInfo) throws Exception {
        List<Costtype> costtypes = costtypeDao.getCosttypesByPage(pageInfo);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(costtypes).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Costtype>(messageEnum.getCode(),messageEnum.getMessage(),costtypes,pageInfo);
    }

    @Override
    public DTO<Costtype> updateCosttypeByCono(Costtype costtype) throws Exception {
        Integer result = costtypeDao.updateCosttypeByCono(costtype);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEADMINSUCCESS:MessageEnum.UPDATEADMINFAIL;
        return new DTO<Costtype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Costtype> addCosttype(Costtype costtype) throws Exception {
        Integer result = costtypeDao.addCosttype(costtype);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.ADDADMINSUCCESS:MessageEnum.ADDADMINFAIL;
        return new DTO<Costtype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    /**
     * 学生选课成功 学生成绩加1分，从选课信息中可以获得学生的学号就能查询出学生原来的成绩
     * @param sc
     * @return
     * @throws Exception
     */

}
